package com.coderside.fragment.io;

import java.io.File;
import java.io.IOException;

public class FileHandler {

	/**
	 *  获取Java Project下的src下指定目录的文件路径.
	 * @param confPath
	 * @return
	 */
	public static String getJavaFilePath(String confPath) {
		//获取系统路径
		String sysPath = System.getProperty("user.dir");
		String filePath = confPath.replace(".", File.separator);
		//系统路径转换成文件路径
		String path = sysPath + File.separator + "src" + File.separator + filePath;
		return path;
	}

	/**
	 * 递归解析java文件,然后再调用回归函数处理解析过程
	 * 如果是文件夹的是递归解析
	 * @param file
	 * @throws IOException
	 */
	public static void parseJavaFile(File file, String confPath, CallBack callBack) throws IOException {
		File[] listFile = null;
		if (file.isDirectory()) {
			listFile = file.listFiles();
		} else {
			callBack.execute(file, confPath);
		}

		for (File f : listFile) {
			if (f.isDirectory()) {
				parseJavaFile(f, confPath, callBack);
			} else {
				callBack.execute(f, confPath);
			}
		}
	}
}
